#!/bin/sh
# -*- tcl -*-
# The next line is executed by /bin/sh, but not tcl \
exec tclsh "$0" ${1+"$@"}

# Test for delete/change/yank from the first character of one line
# to a search that matches at the start of a different line.
#
# three
# one	<- cursor on the 'o'
# four
# one
# five
#
# d/one[enter] leaves
#
# three
#
# one
# five
#
# when it should leave
#
# three
# one
# five
#
# Was https://github.com/martinwguy/xvi/issues/101

source scripts/term
start_vi

# Command to reset the intiial test pattern
set init "1GdGathree\rone\rfour\rone\rfive[esc]2G"
# Match for the initial test pattern
set pattern [list "three" "one" "four" "one" "five" "~"]

# Make classic vi update the screen instead of leaving @ signs in deleted lines
exp_send ":se redraw\r"

# Tests wth delete

test 10 $init		2 0 $pattern
test 11 "d/one\r"	2 0 [list "three" "one" "five" "~"]

# The same thing the other way round
test 12 $init		2 0 $pattern
test 13 "4Gd/one\r"	2 0 [list "three" "one" "five" "~"]

# From a position that's not at the start of a line
test 14 $init		2 0 $pattern
test 15 "ld/one\r"	2 0 [list "three" "o" "one" "five" "~"]

# To a match that doesn't start at the beginning of a line
test 16 $init		2 0 $pattern
test 17 "d/ive\r"	2 0 [list "three" "ive" "~"]

# Tests with yank-put

# Yank from start of line to start of line, put on the "f" of "five"
test 20 $init		2 0 $pattern
test 21 "y/one\rGp"	6 0 [list "three" "one" "four" "one" "five" "one" "four" "~"]
# The same thing not from start of line
test 22 $init		2 0 $pattern
test 23 "ly/one\rGp"	5 1 [list "three" "one" "four" "one" "fne" "fourive" "~"]
# The same thing not to start of line
test 24 $init		2 0 $pattern
test 25 "y/our\rGp"	5 1 [list "three" "one" "four" "one" "fone" "five" "~"]

# Tests with change

test 30 $init		2 0 $pattern
test 31 "c/one\rX[esc]"	2 0 [list "three" "X" "one" "five" "~"]

# Not from start of line.
# This test fails, and is disabled here because it's a different bug. See 154.
#test 32 $init		2 0 $pattern
#test 33 "lc/one\rX[esc]" 2 1 [list "three" "oX" "one" "five" "~"]
# xvi gets this wrong, giving 2 0 [list "three" "Xo" "one" "five"]
# nvi gets this wrong, giving 2 0 [list "three" "X" "one" "five"]

# Range from start of line to not start of line
test 34 $init		2 0 $pattern
test 35 "c/our\rX[esc]" 2 0 [list "three" "Xour" "one" "five" "~"]

stop_vi

exit 0
